<?php
	//待处理订单详情表 定时关闭 普通订单24小时  团购订单3分钟
	file_put_contents("dingshi.txt", date("Y-m-d H:i:s") . "执行定时任务！订单定时关闭" . "\r\n", FILE_APPEND);
	$redis =connectRedis();
	$redis->set('close_order_list',null);
	$close_order_list = $redis->get('close_order_list');
	if($close_order_list==null){
		$close_rs=M('order')->field('order_id,order_sn,add_time,tuanselect')->where("order_state='10'")->select();
		
		$close_newdata=array();
		if($close_rs){
			foreach($close_rs as $key=>$value){
				if($value['tuanselect']==1){
					$close_data['order_id']=$value['order_id'];
					$close_data['order']=$value['order_sn'];
					$close_data['add_time']=$value['add_time'];
					$close_data['clostime']=60*3;
					$close_newdata[]=$data;
				}else{
					$close_data['order_id']=$value['order_id'];
					$close_data['order']=$value['order_sn'];
					$close_data['add_time']=$value['add_time'];
					$close_data['clostime']=60*60*24;
					$close_newdata[]=$data;
				}
			}
		}
		
		//待处理订单
		if($close_newdata){
			$close_newdata=json_encode($close_newdata);
			$redis->set('close_order_list',$close_newdata);
			$close_order_list = $redis->get('close_order_list');
		}
	}
	
	if($close_order_list){
		$close_order_list=json_decode($close_order_list,true);
		foreach($close_order_list as $key=>$v){
			$time=time();
			$guoqi_time= (int)$v['add_time']+$v['clostime'];
			if($time>$guoqi_time){
				$o_info=M('order')->field('order_state')->find($v['order_id']);
				if($o_info['order_state']=='10'){
					$o_data['order_id']=$v['order_id'];
					$o_data['order_state']='0';
					M('order')->save($o_data);
					$action_data['order_id']=$v['order_id'];
					$action_data['action']='订单超时';
					$action_data['uid']=0;
					$action_data['user_name']='系统';
					$action_data['order_status']='0';
					$action_data['order_status_text']='订单超时关闭';
					$action_data['action_time']=time();
					M('order_action')->add($action_data);
				}
				unset($close_order_list[$key]);
			}
		}
		$close_order_list=json_encode($close_order_list);
		$redis->set('close_order_list',$close_order_list);
	
	}
	

	
?>